﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
using System.Data.SqlClient;

public partial class user_control_MenuCategory : System.Web.UI.UserControl
{
    SqlConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ShopLaptopConnectionString"].ConnectionString);
        if (!IsPostBack)
        {
            displayMenu();
        }
    }

    //protected void mnCategory_MenuItemClick(object sender, MenuEventArgs e)
    //{
    //    Response.Redirect("default.aspx?cateID=" + mnCategory.SelectedValue);
    //    //SqlCommand cmd = new SqlCommand("Select * from Product where cateid=" + mnCategory.SelectedValue, conn);
    //    //conn.Open();
    //    //SqlDataReader reader = cmd.ExecuteReader();
    //    //dlProduct.DataSource = reader;
    //    //dlProduct.DataBind();
    //    //conn.Close();
    //}

    protected void displayMenu()
    {
        SqlCommand cmd = new SqlCommand("Select * from Category order by CateName", conn);
        conn.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        dlCategory.DataSource = reader;
        dlCategory.DataBind();
        conn.Close();
    }

    protected void dlCategory_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        string cateID = ((Label)e.Item.FindControl("lbCateID")).Text;
        Response.Redirect("default.aspx?cateID=" + cateID);
    }
}
